const app = getApp()
const db = wx.cloud.database()
Page({
  //选择器
  data: {
    suo: true
  },
  // 显示隐藏密码
  suo() {
    this.setData({
      suo: !this.data.suo
    })
  },

  create_login(e) {
    let user = e.detail.value
    user.phone = '13888888888'
    user.password = '111111'
    console.log('user', user)
    if (!user.phone) {
      wx.showToast({
        icon: 'none',
        title: '请填写手机',
      })
    } else if (!user.password) {
      wx.showToast({
        icon: 'none',
        title: '请填写密码',
      })
    } else {
      db.collection('user').where({
          phone: user.phone,
          password: user.password
        }).get()
        .then(res => {
          console.log('获取登录结果', res)
          let users = res.data
          if (users && users.length > 0) {
            let user = users[0]
            if (user.status == '审核通过') {
              app._saveUserInfo(user)
              wx.switchTab({
                url: '/pages/index/index',
              })
            } else if (user.status == '拒绝') {
              wx.showToast({
                title: '被管理员拒绝',
                icon: "error"
              })
            } else {
              wx.showToast({
                title: '还未审核通过',
                icon: "error"
              })
            }
          } else {
            wx.showToast({
              title: '账号密码错误',
              icon: "error"
            })
          }
        })
        .catch(res => {
          console.log('获取登录结果失败', res)
        })
    }
  },
  // 去注册
  zhuce(res) {
    wx.navigateTo({
      url: '/pages/register/register',
    })
  },
  admin(res) {
    wx.navigateTo({
      url: '/pages/admin-login/admin-login',
    })
  },

})